<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>NumPy Distutils - Users Guide &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../about.html" >
    <link rel="index" title="Index" href="../genindex.html" >
    <link rel="search" title="Search" href="../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../index.html" >
    <link rel="up" title="NumPy Reference" href="index.html" >
    <link rel="next" title="NumPy C-API" href="c-api/index.html" >
    <link rel="prev" title="numpy.distutils.system_info.get_standard_file" href="generated/numpy.distutils.system_info.get_standard_file.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../index.html">
      <img border=0 alt="NumPy" src="../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="index.html" accesskey="U">NumPy Reference</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="c-api/index.html" title="NumPy C-API"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="generated/numpy.distutils.system_info.get_standard_file.html" title="numpy.distutils.system_info.get_standard_file"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">NumPy Distutils - Users Guide</a><ul>
<li><a class="reference internal" href="#scipy-structure">SciPy structure</a></li>
<li><a class="reference internal" href="#requirements-for-scipy-packages">Requirements for SciPy packages</a></li>
<li><a class="reference internal" href="#the-setup-py-file">The <code class="docutils literal notranslate"><span class="pre">setup.py</span></code> file</a><ul>
<li><a class="reference internal" href="#scipy-pure-python-package-example">SciPy pure Python package example</a></li>
<li><a class="reference internal" href="#configuration-instance-attributes"><code class="docutils literal notranslate"><span class="pre">Configuration</span></code> instance attributes</a></li>
<li><a class="reference internal" href="#configuration-instance-methods"><code class="docutils literal notranslate"><span class="pre">Configuration</span></code> instance methods</a></li>
<li><a class="reference internal" href="#conversion-of-src-files-using-templates">Conversion of <code class="docutils literal notranslate"><span class="pre">.src</span></code> files using Templates</a></li>
<li><a class="reference internal" href="#fortran-files">Fortran files</a><ul>
<li><a class="reference internal" href="#named-repeat-rule">Named repeat rule</a></li>
<li><a class="reference internal" href="#short-repeat-rule">Short repeat rule</a></li>
<li><a class="reference internal" href="#pre-defined-names">Pre-defined names</a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-files">Other files</a></li>
<li><a class="reference internal" href="#useful-functions-in-numpy-distutils-misc-util">Useful functions in <code class="docutils literal notranslate"><span class="pre">numpy.distutils.misc_util</span></code></a></li>
<li><a class="reference internal" href="#numpy-distutils-system-info-module"><code class="docutils literal notranslate"><span class="pre">numpy.distutils.system_info</span></code> module</a></li>
<li><a class="reference internal" href="#numpy-distutils-cpuinfo-module"><code class="docutils literal notranslate"><span class="pre">numpy.distutils.cpuinfo</span></code> module</a></li>
<li><a class="reference internal" href="#numpy-distutils-log-module"><code class="docutils literal notranslate"><span class="pre">numpy.distutils.log</span></code> module</a></li>
<li><a class="reference internal" href="#numpy-distutils-exec-command-module"><code class="docutils literal notranslate"><span class="pre">numpy.distutils.exec_command</span></code> module</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-init-py-file">The <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code> file</a></li>
<li><a class="reference internal" href="#extra-features-in-numpy-distutils">Extra features in NumPy Distutils</a><ul>
<li><a class="reference internal" href="#specifying-config-fc-options-for-libraries-in-setup-py-script">Specifying config_fc options for libraries in setup.py script</a></li>
<li><a class="reference internal" href="#getting-extra-fortran-77-compiler-options-from-source">Getting extra Fortran 77 compiler options from source</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="generated/numpy.distutils.system_info.get_standard_file.html"
                        title="previous chapter">numpy.distutils.system_info.get_standard_file</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="c-api/index.html"
                        title="next chapter">NumPy C-API</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="numpy-distutils-users-guide">
<span id="distutils-user-guide"></span><h1>NumPy Distutils - Users Guide<a class="headerlink" href="#numpy-distutils-users-guide" title="Permalink to this headline">¶</a></h1>
<div class="section" id="scipy-structure">
<h2>SciPy structure<a class="headerlink" href="#scipy-structure" title="Permalink to this headline">¶</a></h2>
<p>Currently SciPy project consists of two packages:</p>
<ul class="simple">
<li><p>NumPy — it provides packages like:</p>
<ul>
<li><p>numpy.distutils - extension to Python distutils</p></li>
<li><p>numpy.f2py - a tool to bind Fortran/C codes to Python</p></li>
<li><p>numpy.core - future replacement of Numeric and numarray packages</p></li>
<li><p>numpy.lib - extra utility functions</p></li>
<li><p>numpy.testing - numpy-style tools for unit testing</p></li>
<li><p>etc</p></li>
</ul>
</li>
<li><p>SciPy — a collection of scientific tools for Python.</p></li>
</ul>
<p>The aim of this document is to describe how to add new tools to SciPy.</p>
</div>
<div class="section" id="requirements-for-scipy-packages">
<h2>Requirements for SciPy packages<a class="headerlink" href="#requirements-for-scipy-packages" title="Permalink to this headline">¶</a></h2>
<p>SciPy consists of Python packages, called SciPy packages, that are
available to Python users via the <code class="docutils literal notranslate"><span class="pre">scipy</span></code> namespace. Each SciPy package
may contain other SciPy packages. And so on. Therefore, the SciPy
directory tree is a tree of packages with arbitrary depth and width.
Any SciPy package may depend on NumPy packages but the dependence on other
SciPy packages should be kept minimal or zero.</p>
<p>A SciPy package contains, in addition to its sources, the following
files and directories:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">setup.py</span></code> — building script</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">__init__.py</span></code> — package initializer</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">tests/</span></code> — directory of unittests</p></li>
</ul>
</div></blockquote>
<p>Their contents are described below.</p>
</div>
<div class="section" id="the-setup-py-file">
<h2>The <code class="docutils literal notranslate"><span class="pre">setup.py</span></code> file<a class="headerlink" href="#the-setup-py-file" title="Permalink to this headline">¶</a></h2>
<p>In order to add a Python package to SciPy, its build script (<code class="docutils literal notranslate"><span class="pre">setup.py</span></code>)
must meet certain requirements. The most important requirement is that the
package define a <code class="docutils literal notranslate"><span class="pre">configuration(parent_package='',top_path=None)</span></code> function
which returns a dictionary suitable for passing to
<code class="docutils literal notranslate"><span class="pre">numpy.distutils.core.setup(..)</span></code>. To simplify the construction of
this dictionary, <code class="docutils literal notranslate"><span class="pre">numpy.distutils.misc_util</span></code> provides the
<code class="docutils literal notranslate"><span class="pre">Configuration</span></code> class, described below.</p>
<div class="section" id="scipy-pure-python-package-example">
<h3>SciPy pure Python package example<a class="headerlink" href="#scipy-pure-python-package-example" title="Permalink to this headline">¶</a></h3>
<p>Below is an example of a minimal <code class="docutils literal notranslate"><span class="pre">setup.py</span></code> file for a pure SciPy package:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
<span class="k">def</span> <span class="nf">configuration</span><span class="p">(</span><span class="n">parent_package</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">top_path</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="kn">from</span> <span class="nn">numpy.distutils.misc_util</span> <span class="kn">import</span> <span class="n">Configuration</span>
    <span class="n">config</span> <span class="o">=</span> <span class="n">Configuration</span><span class="p">(</span><span class="s1">&#39;mypackage&#39;</span><span class="p">,</span><span class="n">parent_package</span><span class="p">,</span><span class="n">top_path</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">config</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">numpy.distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
    <span class="c1">#setup(**configuration(top_path=&#39;&#39;).todict())</span>
    <span class="n">setup</span><span class="p">(</span><span class="n">configuration</span><span class="o">=</span><span class="n">configuration</span><span class="p">)</span>
</pre></div>
</div>
<p>The arguments of the <code class="docutils literal notranslate"><span class="pre">configuration</span></code> function specify the name of
parent SciPy package (<code class="docutils literal notranslate"><span class="pre">parent_package</span></code>) and the directory location
of the main <code class="docutils literal notranslate"><span class="pre">setup.py</span></code> script (<code class="docutils literal notranslate"><span class="pre">top_path</span></code>).  These arguments,
along with the name of the current package, should be passed to the
<code class="docutils literal notranslate"><span class="pre">Configuration</span></code> constructor.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">Configuration</span></code> constructor has a fourth optional argument,
<code class="docutils literal notranslate"><span class="pre">package_path</span></code>, that can be used when package files are located in
a different location than the directory of the <code class="docutils literal notranslate"><span class="pre">setup.py</span></code> file.</p>
<p>Remaining <code class="docutils literal notranslate"><span class="pre">Configuration</span></code> arguments are all keyword arguments that will
be used to initialize attributes of <code class="docutils literal notranslate"><span class="pre">Configuration</span></code>
instance. Usually, these keywords are the same as the ones that
<code class="docutils literal notranslate"><span class="pre">setup(..)</span></code> function would expect, for example, <code class="docutils literal notranslate"><span class="pre">packages</span></code>,
<code class="docutils literal notranslate"><span class="pre">ext_modules</span></code>, <code class="docutils literal notranslate"><span class="pre">data_files</span></code>, <code class="docutils literal notranslate"><span class="pre">include_dirs</span></code>, <code class="docutils literal notranslate"><span class="pre">libraries</span></code>,
<code class="docutils literal notranslate"><span class="pre">headers</span></code>, <code class="docutils literal notranslate"><span class="pre">scripts</span></code>, <code class="docutils literal notranslate"><span class="pre">package_dir</span></code>, etc.  However, the direct
specification of these keywords is not recommended as the content of
these keyword arguments will not be processed or checked for the
consistency of SciPy building system.</p>
<p>Finally, <code class="docutils literal notranslate"><span class="pre">Configuration</span></code> has <code class="docutils literal notranslate"><span class="pre">.todict()</span></code> method that returns all
the configuration data as a dictionary suitable for passing on to the
<code class="docutils literal notranslate"><span class="pre">setup(..)</span></code> function.</p>
</div>
<div class="section" id="configuration-instance-attributes">
<h3><code class="docutils literal notranslate"><span class="pre">Configuration</span></code> instance attributes<a class="headerlink" href="#configuration-instance-attributes" title="Permalink to this headline">¶</a></h3>
<p>In addition to attributes that can be specified via keyword arguments
to <code class="docutils literal notranslate"><span class="pre">Configuration</span></code> constructor, <code class="docutils literal notranslate"><span class="pre">Configuration</span></code> instance (let us
denote as <code class="docutils literal notranslate"><span class="pre">config</span></code>) has the following attributes that can be useful
in writing setup scripts:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">config.name</span></code> - full name of the current package. The names of parent
packages can be extracted as <code class="docutils literal notranslate"><span class="pre">config.name.split('.')</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.local_path</span></code> - path to the location of current <code class="docutils literal notranslate"><span class="pre">setup.py</span></code> file.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.top_path</span></code> - path to the location of main <code class="docutils literal notranslate"><span class="pre">setup.py</span></code> file.</p></li>
</ul>
</div>
<div class="section" id="configuration-instance-methods">
<h3><code class="docutils literal notranslate"><span class="pre">Configuration</span></code> instance methods<a class="headerlink" href="#configuration-instance-methods" title="Permalink to this headline">¶</a></h3>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">config.todict()</span></code> — returns configuration dictionary suitable for
passing to <code class="docutils literal notranslate"><span class="pre">numpy.distutils.core.setup(..)</span></code> function.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.paths(*paths)</span> <span class="pre">---</span> <span class="pre">applies</span> <span class="pre">``glob.glob(..)</span></code> to items of
<code class="docutils literal notranslate"><span class="pre">paths</span></code> if necessary. Fixes <code class="docutils literal notranslate"><span class="pre">paths</span></code> item that is relative to
<code class="docutils literal notranslate"><span class="pre">config.local_path</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.get_subpackage(subpackage_name,subpackage_path=None)</span></code> —
returns a list of subpackage configurations. Subpackage is looked in the
current directory under the name <code class="docutils literal notranslate"><span class="pre">subpackage_name</span></code> but the path
can be specified also via optional <code class="docutils literal notranslate"><span class="pre">subpackage_path</span></code> argument.
If <code class="docutils literal notranslate"><span class="pre">subpackage_name</span></code> is specified as <code class="docutils literal notranslate"><span class="pre">None</span></code> then the subpackage
name will be taken the basename of <code class="docutils literal notranslate"><span class="pre">subpackage_path</span></code>.
Any <code class="docutils literal notranslate"><span class="pre">*</span></code> used for subpackage names are expanded as wildcards.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.add_subpackage(subpackage_name,subpackage_path=None)</span></code> —
add SciPy subpackage configuration to the current one. The meaning
and usage of arguments is explained above, see
<code class="docutils literal notranslate"><span class="pre">config.get_subpackage()</span></code> method.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.add_data_files(*files)</span></code> — prepend <code class="docutils literal notranslate"><span class="pre">files</span></code> to <code class="docutils literal notranslate"><span class="pre">data_files</span></code>
list. If <code class="docutils literal notranslate"><span class="pre">files</span></code> item is a tuple then its first element defines
the suffix of where data files are copied relative to package installation
directory and the second element specifies the path to data
files. By default data files are copied under package installation
directory. For example,</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">config</span><span class="o">.</span><span class="n">add_data_files</span><span class="p">(</span><span class="s1">&#39;foo.dat&#39;</span><span class="p">,</span>
                      <span class="p">(</span><span class="s1">&#39;fun&#39;</span><span class="p">,[</span><span class="s1">&#39;gun.dat&#39;</span><span class="p">,</span><span class="s1">&#39;nun/pun.dat&#39;</span><span class="p">,</span><span class="s1">&#39;/tmp/sun.dat&#39;</span><span class="p">]),</span>
                      <span class="s1">&#39;bar/car.dat&#39;</span><span class="o">.</span>
                      <span class="s1">&#39;/full/path/to/can.dat&#39;</span><span class="p">,</span>
                      <span class="p">)</span>
</pre></div>
</div>
<p>will install data files to the following locations</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">installation</span> <span class="n">path</span> <span class="n">of</span> <span class="n">config</span><span class="o">.</span><span class="n">name</span> <span class="n">package</span><span class="o">&gt;/</span>
  <span class="n">foo</span><span class="o">.</span><span class="n">dat</span>
  <span class="n">fun</span><span class="o">/</span>
    <span class="n">gun</span><span class="o">.</span><span class="n">dat</span>
    <span class="n">pun</span><span class="o">.</span><span class="n">dat</span>
    <span class="n">sun</span><span class="o">.</span><span class="n">dat</span>
  <span class="n">bar</span><span class="o">/</span>
    <span class="n">car</span><span class="o">.</span><span class="n">dat</span>
  <span class="n">can</span><span class="o">.</span><span class="n">dat</span>
</pre></div>
</div>
<p>Path to data files can be a function taking no arguments and
returning path(s) to data files – this is a useful when data files
are generated while building the package. (XXX: explain the step
when this function are called exactly)</p>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.add_data_dir(data_path)</span></code> — add directory <code class="docutils literal notranslate"><span class="pre">data_path</span></code>
recursively to <code class="docutils literal notranslate"><span class="pre">data_files</span></code>. The whole directory tree starting at
<code class="docutils literal notranslate"><span class="pre">data_path</span></code> will be copied under package installation directory.
If <code class="docutils literal notranslate"><span class="pre">data_path</span></code> is a tuple then its first element defines
the suffix of where data files are copied relative to package installation
directory and the second element specifies the path to data directory.
By default, data directory are copied under package installation
directory under the basename of <code class="docutils literal notranslate"><span class="pre">data_path</span></code>. For example,</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">config</span><span class="o">.</span><span class="n">add_data_dir</span><span class="p">(</span><span class="s1">&#39;fun&#39;</span><span class="p">)</span>  <span class="c1"># fun/ contains foo.dat bar/car.dat</span>
<span class="n">config</span><span class="o">.</span><span class="n">add_data_dir</span><span class="p">((</span><span class="s1">&#39;sun&#39;</span><span class="p">,</span><span class="s1">&#39;fun&#39;</span><span class="p">))</span>
<span class="n">config</span><span class="o">.</span><span class="n">add_data_dir</span><span class="p">((</span><span class="s1">&#39;gun&#39;</span><span class="p">,</span><span class="s1">&#39;/full/path/to/fun&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>will install data files to the following locations</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">installation</span> <span class="n">path</span> <span class="n">of</span> <span class="n">config</span><span class="o">.</span><span class="n">name</span> <span class="n">package</span><span class="o">&gt;/</span>
  <span class="n">fun</span><span class="o">/</span>
     <span class="n">foo</span><span class="o">.</span><span class="n">dat</span>
     <span class="n">bar</span><span class="o">/</span>
        <span class="n">car</span><span class="o">.</span><span class="n">dat</span>
  <span class="n">sun</span><span class="o">/</span>
     <span class="n">foo</span><span class="o">.</span><span class="n">dat</span>
     <span class="n">bar</span><span class="o">/</span>
        <span class="n">car</span><span class="o">.</span><span class="n">dat</span>
  <span class="n">gun</span><span class="o">/</span>
     <span class="n">foo</span><span class="o">.</span><span class="n">dat</span>
     <span class="n">bar</span><span class="o">/</span>
        <span class="n">car</span><span class="o">.</span><span class="n">dat</span>
</pre></div>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.add_include_dirs(*paths)</span></code> — prepend <code class="docutils literal notranslate"><span class="pre">paths</span></code> to
<code class="docutils literal notranslate"><span class="pre">include_dirs</span></code> list. This list will be visible to all extension
modules of the current package.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.add_headers(*files)</span></code> — prepend <code class="docutils literal notranslate"><span class="pre">files</span></code> to <code class="docutils literal notranslate"><span class="pre">headers</span></code>
list. By default, headers will be installed under
<code class="docutils literal notranslate"><span class="pre">&lt;prefix&gt;/include/pythonX.X/&lt;config.name.replace('.','/')&gt;/</span></code>
directory. If <code class="docutils literal notranslate"><span class="pre">files</span></code> item is a tuple then it’s first argument
specifies the installation suffix relative to
<code class="docutils literal notranslate"><span class="pre">&lt;prefix&gt;/include/pythonX.X/</span></code> path.  This is a Python distutils
method; its use is discouraged for NumPy and SciPy in favour of
<code class="docutils literal notranslate"><span class="pre">config.add_data_files(*files)</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.add_scripts(*files)</span></code> — prepend <code class="docutils literal notranslate"><span class="pre">files</span></code> to <code class="docutils literal notranslate"><span class="pre">scripts</span></code>
list. Scripts will be installed under <code class="docutils literal notranslate"><span class="pre">&lt;prefix&gt;/bin/</span></code> directory.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.add_extension(name,sources,**kw)</span></code> — create and add an
<code class="docutils literal notranslate"><span class="pre">Extension</span></code> instance to <code class="docutils literal notranslate"><span class="pre">ext_modules</span></code> list. The first argument
<code class="docutils literal notranslate"><span class="pre">name</span></code> defines the name of the extension module that will be
installed under <code class="docutils literal notranslate"><span class="pre">config.name</span></code> package. The second argument is
a list of sources. <code class="docutils literal notranslate"><span class="pre">add_extension</span></code> method takes also keyword
arguments that are passed on to the <code class="docutils literal notranslate"><span class="pre">Extension</span></code> constructor.
The list of allowed keywords is the following: <code class="docutils literal notranslate"><span class="pre">include_dirs</span></code>,
<code class="docutils literal notranslate"><span class="pre">define_macros</span></code>, <code class="docutils literal notranslate"><span class="pre">undef_macros</span></code>, <code class="docutils literal notranslate"><span class="pre">library_dirs</span></code>, <code class="docutils literal notranslate"><span class="pre">libraries</span></code>,
<code class="docutils literal notranslate"><span class="pre">runtime_library_dirs</span></code>, <code class="docutils literal notranslate"><span class="pre">extra_objects</span></code>, <code class="docutils literal notranslate"><span class="pre">extra_compile_args</span></code>,
<code class="docutils literal notranslate"><span class="pre">extra_link_args</span></code>, <code class="docutils literal notranslate"><span class="pre">export_symbols</span></code>, <code class="docutils literal notranslate"><span class="pre">swig_opts</span></code>, <code class="docutils literal notranslate"><span class="pre">depends</span></code>,
<code class="docutils literal notranslate"><span class="pre">language</span></code>, <code class="docutils literal notranslate"><span class="pre">f2py_options</span></code>, <code class="docutils literal notranslate"><span class="pre">module_dirs</span></code>, <code class="docutils literal notranslate"><span class="pre">extra_info</span></code>,
<code class="docutils literal notranslate"><span class="pre">extra_f77_compile_args</span></code>, <code class="docutils literal notranslate"><span class="pre">extra_f90_compile_args</span></code>.</p>
<p>Note that <code class="docutils literal notranslate"><span class="pre">config.paths</span></code> method is applied to all lists that
may contain paths. <code class="docutils literal notranslate"><span class="pre">extra_info</span></code> is a dictionary or a list
of dictionaries that content will be appended to keyword arguments.
The list <code class="docutils literal notranslate"><span class="pre">depends</span></code> contains paths to files or directories
that the sources of the extension module depend on. If any path
in the <code class="docutils literal notranslate"><span class="pre">depends</span></code> list is newer than the extension module, then
the module will be rebuilt.</p>
<p>The list of sources may contain functions (‘source generators’)
with a pattern <code class="docutils literal notranslate"><span class="pre">def</span> <span class="pre">&lt;funcname&gt;(ext,</span> <span class="pre">build_dir):</span> <span class="pre">return</span>
<span class="pre">&lt;source(s)</span> <span class="pre">or</span> <span class="pre">None&gt;</span></code>. If <code class="docutils literal notranslate"><span class="pre">funcname</span></code> returns <code class="docutils literal notranslate"><span class="pre">None</span></code>, no sources
are generated. And if the <code class="docutils literal notranslate"><span class="pre">Extension</span></code> instance has no sources
after processing all source generators, no extension module will
be built. This is the recommended way to conditionally define
extension modules. Source generator functions are called by the
<code class="docutils literal notranslate"><span class="pre">build_src</span></code> sub-command of <code class="docutils literal notranslate"><span class="pre">numpy.distutils</span></code>.</p>
<p>For example, here is a typical source generator function:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">generate_source</span><span class="p">(</span><span class="n">ext</span><span class="p">,</span><span class="n">build_dir</span><span class="p">):</span>
    <span class="kn">import</span> <span class="nn">os</span>
    <span class="kn">from</span> <span class="nn">distutils.dep_util</span> <span class="kn">import</span> <span class="n">newer</span>
    <span class="n">target</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">build_dir</span><span class="p">,</span><span class="s1">&#39;somesource.c&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">newer</span><span class="p">(</span><span class="n">target</span><span class="p">,</span><span class="vm">__file__</span><span class="p">):</span>
        <span class="c1"># create target file</span>
    <span class="k">return</span> <span class="n">target</span>
</pre></div>
</div>
<p>The first argument contains the Extension instance that can be
useful to access its attributes like <code class="docutils literal notranslate"><span class="pre">depends</span></code>, <code class="docutils literal notranslate"><span class="pre">sources</span></code>,
etc. lists and modify them during the building process.
The second argument gives a path to a build directory that must
be used when creating files to a disk.</p>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.add_library(name,</span> <span class="pre">sources,</span> <span class="pre">**build_info)</span></code> — add a
library to <code class="docutils literal notranslate"><span class="pre">libraries</span></code> list. Allowed keywords arguments are
<code class="docutils literal notranslate"><span class="pre">depends</span></code>, <code class="docutils literal notranslate"><span class="pre">macros</span></code>, <code class="docutils literal notranslate"><span class="pre">include_dirs</span></code>, <code class="docutils literal notranslate"><span class="pre">extra_compiler_args</span></code>,
<code class="docutils literal notranslate"><span class="pre">f2py_options</span></code>, <code class="docutils literal notranslate"><span class="pre">extra_f77_compile_args</span></code>,
<code class="docutils literal notranslate"><span class="pre">extra_f90_compile_args</span></code>.  See <code class="docutils literal notranslate"><span class="pre">.add_extension()</span></code> method for
more information on arguments.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.have_f77c()</span></code> — return True if Fortran 77 compiler is
available (read: a simple Fortran 77 code compiled successfully).</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.have_f90c()</span></code> — return True if Fortran 90 compiler is
available (read: a simple Fortran 90 code compiled successfully).</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.get_version()</span></code> — return version string of the current package,
<code class="docutils literal notranslate"><span class="pre">None</span></code> if version information could not be detected. This methods
scans files <code class="docutils literal notranslate"><span class="pre">__version__.py</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;packagename&gt;_version.py</span></code>,
<code class="docutils literal notranslate"><span class="pre">version.py</span></code>, <code class="docutils literal notranslate"><span class="pre">__svn_version__.py</span></code> for string variables
<code class="docutils literal notranslate"><span class="pre">version</span></code>, <code class="docutils literal notranslate"><span class="pre">__version__</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;packagename&gt;_version</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.make_svn_version_py()</span></code> — appends a data function to
<code class="docutils literal notranslate"><span class="pre">data_files</span></code> list that will generate <code class="docutils literal notranslate"><span class="pre">__svn_version__.py</span></code> file
to the current package directory. The file will be removed from
the source directory when Python exits.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.get_build_temp_dir()</span></code> — return a path to a temporary
directory. This is the place where one should build temporary
files.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.get_distribution()</span></code> — return distutils <code class="docutils literal notranslate"><span class="pre">Distribution</span></code>
instance.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.get_config_cmd()</span></code> — returns <code class="docutils literal notranslate"><span class="pre">numpy.distutils</span></code> config
command instance.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">config.get_info(*names)</span></code> —</p></li>
</ul>
</div>
<div class="section" id="conversion-of-src-files-using-templates">
<span id="templating"></span><h3>Conversion of <code class="docutils literal notranslate"><span class="pre">.src</span></code> files using Templates<a class="headerlink" href="#conversion-of-src-files-using-templates" title="Permalink to this headline">¶</a></h3>
<p>NumPy distutils supports automatic conversion of source files named
&lt;somefile&gt;.src. This facility can be used to maintain very similar
code blocks requiring only simple changes between blocks. During the
build phase of setup, if a template file named &lt;somefile&gt;.src is
encountered, a new file named &lt;somefile&gt; is constructed from the
template and placed in the build directory to be used instead. Two
forms of template conversion are supported. The first form occurs for
files named &lt;file&gt;.ext.src where ext is a recognized Fortran
extension (f, f90, f95, f77, for, ftn, pyf). The second form is used
for all other cases.</p>
</div>
<div class="section" id="fortran-files">
<span id="index-0"></span><h3>Fortran files<a class="headerlink" href="#fortran-files" title="Permalink to this headline">¶</a></h3>
<p>This template converter will replicate all <strong>function</strong> and
<strong>subroutine</strong> blocks in the file with names that contain ‘&lt;…&gt;’
according to the rules in ‘&lt;…&gt;’. The number of comma-separated words
in ‘&lt;…&gt;’ determines the number of times the block is repeated. What
these words are indicates what that repeat rule, ‘&lt;…&gt;’, should be
replaced with in each block. All of the repeat rules in a block must
contain the same number of comma-separated words indicating the number
of times that block should be repeated. If the word in the repeat rule
needs a comma, leftarrow, or rightarrow, then prepend it with a
backslash ‘ ‘. If a word in the repeat rule matches ‘ \&lt;index&gt;’ then
it will be replaced with the &lt;index&gt;-th word in the same repeat
specification. There are two forms for the repeat rule: named and
short.</p>
<div class="section" id="named-repeat-rule">
<h4>Named repeat rule<a class="headerlink" href="#named-repeat-rule" title="Permalink to this headline">¶</a></h4>
<p>A named repeat rule is useful when the same set of repeats must be
used several times in a block. It is specified using &lt;rule1=item1,
item2, item3,…, itemN&gt;, where N is the number of times the block
should be repeated. On each repeat of the block, the entire
expression, ‘&lt;…&gt;’ will be replaced first with item1, and then with
item2, and so forth until N repeats are accomplished. Once a named
repeat specification has been introduced, the same repeat rule may be
used <strong>in the current block</strong> by referring only to the name
(i.e. &lt;rule1&gt;.</p>
</div>
<div class="section" id="short-repeat-rule">
<h4>Short repeat rule<a class="headerlink" href="#short-repeat-rule" title="Permalink to this headline">¶</a></h4>
<p>A short repeat rule looks like &lt;item1, item2, item3, …, itemN&gt;. The
rule specifies that the entire expression, ‘&lt;…&gt;’ should be replaced
first with item1, and then with item2, and so forth until N repeats
are accomplished.</p>
</div>
<div class="section" id="pre-defined-names">
<h4>Pre-defined names<a class="headerlink" href="#pre-defined-names" title="Permalink to this headline">¶</a></h4>
<p>The following predefined named repeat rules are available:</p>
<ul class="simple">
<li><p>&lt;prefix=s,d,c,z&gt;</p></li>
<li><p>&lt;_c=s,d,c,z&gt;</p></li>
<li><p>&lt;_t=real, double precision, complex, double complex&gt;</p></li>
<li><p>&lt;ftype=real, double precision, complex, double complex&gt;</p></li>
<li><p>&lt;ctype=float, double, complex_float, complex_double&gt;</p></li>
<li><p>&lt;ftypereal=float, double precision, \0, \1&gt;</p></li>
<li><p>&lt;ctypereal=float, double, \0, \1&gt;</p></li>
</ul>
</div>
</div>
<div class="section" id="other-files">
<h3>Other files<a class="headerlink" href="#other-files" title="Permalink to this headline">¶</a></h3>
<p>Non-Fortran files use a separate syntax for defining template blocks
that should be repeated using a variable expansion similar to the
named repeat rules of the Fortran-specific repeats.</p>
<p>NumPy Distutils preprocesses C source files (extension: <code class="file docutils literal notranslate"><span class="pre">.c.src</span></code>) written
in a custom templating language to generate C code. The <code class="xref c c-data docutils literal notranslate"><span class="pre">&#64;</span></code> symbol is
used to wrap macro-style variables to empower a string substitution mechanism
that might describe (for instance) a set of data types.</p>
<p>The template language blocks are delimited by <code class="xref c c-data docutils literal notranslate"><span class="pre">/**begin</span> <span class="pre">repeat</span></code>
and <code class="xref c c-data docutils literal notranslate"><span class="pre">/**end</span> <span class="pre">repeat**/</span></code> lines, which may also be nested using
consecutively numbered delimiting lines such as <code class="xref c c-data docutils literal notranslate"><span class="pre">/**begin</span> <span class="pre">repeat1</span></code>
and <code class="xref c c-data docutils literal notranslate"><span class="pre">/**end</span> <span class="pre">repeat1**/</span></code>:</p>
<p>1. “/**begin repeat “on a line by itself marks the beginning of
a segment that should be repeated.</p>
<p>2. Named variable expansions are defined using <code class="docutils literal notranslate"><span class="pre">#name=item1,</span> <span class="pre">item2,</span> <span class="pre">item3,</span>
<span class="pre">...,</span> <span class="pre">itemN#</span></code> and placed on successive lines. These variables are
replaced in each repeat block with corresponding word. All named
variables in the same repeat block must define the same number of
words.</p>
<p>3. In specifying the repeat rule for a named variable, <code class="docutils literal notranslate"><span class="pre">item*N</span></code> is short-
hand for <code class="docutils literal notranslate"><span class="pre">item,</span> <span class="pre">item,</span> <span class="pre">...,</span> <span class="pre">item</span></code> repeated N times. In addition,
parenthesis in combination with *N can be used for grouping several
items that should be repeated. Thus, #name=(item1, item2)*4# is
equivalent to #name=item1, item2, item1, item2, item1, item2, item1,
item2#</p>
<p>4. “*/ “on a line by itself marks the end of the variable expansion
naming. The next line is the first line that will be repeated using
the named rules.</p>
<p>5. Inside the block to be repeated, the variables that should be expanded
are specified as <code class="docutils literal notranslate"><span class="pre">&#64;name&#64;</span></code></p>
<p>6. “/**end repeat**/ “on a line by itself marks the previous line
as the last line of the block to be repeated.</p>
<p>7. A loop in the NumPy C source code may have a <code class="docutils literal notranslate"><span class="pre">&#64;TYPE&#64;</span></code> variable, targeted
for string substitution, which is preprocessed to a number of otherwise
identical loops with several strings such as INT, LONG, UINT, ULONG. The
<code class="docutils literal notranslate"><span class="pre">&#64;TYPE&#64;</span></code> style syntax thus reduces code duplication and maintenance burden by
mimicking languages that have generic type support.</p>
<p>The above rules may be clearer in the following template source example:</p>
<div class="highlight-NumPyC notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="cm">/* TIMEDELTA to non-float types */</span>

<span class="hll"> <span class="cm">/**begin repeat</span>
</span><span class="cm">  *</span>
<span class="cm">  * #TOTYPE = BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG,</span>
<span class="cm">  *           LONGLONG, ULONGLONG, DATETIME,</span>
<span class="cm">  *           TIMEDELTA#</span>
<span class="cm">  * #totype = npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, npy_uint,</span>
<span class="cm">  *           npy_long, npy_ulong, npy_longlong, npy_ulonglong,</span>
<span class="cm">  *           npy_datetime, npy_timedelta#</span>
<span class="cm">  */</span>

<span class="hll"> <span class="cm">/**begin repeat1</span>
</span><span class="cm">  *</span>
<span class="cm">  * #FROMTYPE = TIMEDELTA#</span>
<span class="cm">  * #fromtype = npy_timedelta#</span>
<span class="cm">  */</span>
 <span class="k">static</span> <span class="kt">void</span>
 <span class="n">@FROMTYPE@_to_@TOTYPE@</span><span class="p">(</span><span class="kt">void</span> <span class="o">*</span><span class="n">input</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">output</span><span class="p">,</span> <span class="n">npy_intp</span> <span class="n">n</span><span class="p">,</span>
         <span class="kt">void</span> <span class="o">*</span><span class="n">NPY_UNUSED</span><span class="p">(</span><span class="n">aip</span><span class="p">),</span> <span class="kt">void</span> <span class="o">*</span><span class="n">NPY_UNUSED</span><span class="p">(</span><span class="n">aop</span><span class="p">))</span>
 <span class="p">{</span>
     <span class="k">const</span> <span class="n">@fromtype@</span> <span class="o">*</span><span class="n">ip</span> <span class="o">=</span> <span class="n">input</span><span class="p">;</span>
     <span class="n">@totype@</span> <span class="o">*</span><span class="n">op</span> <span class="o">=</span> <span class="n">output</span><span class="p">;</span>

     <span class="k">while</span> <span class="p">(</span><span class="n">n</span><span class="o">--</span><span class="p">)</span> <span class="p">{</span>
         <span class="o">*</span><span class="n">op</span><span class="o">++</span> <span class="o">=</span> <span class="p">(</span><span class="n">@totype@</span><span class="p">)</span><span class="o">*</span><span class="n">ip</span><span class="o">++</span><span class="p">;</span>
     <span class="p">}</span>
 <span class="p">}</span>
<span class="hll"> <span class="cm">/**end repeat1**/</span>
</span>
<span class="hll"> <span class="cm">/**end repeat**/</span>
</span></pre></div>
</td></tr></table></div>
<p>The preprocessing of generically typed C source files (whether in NumPy
proper or in any third party package using NumPy Distutils) is performed
by <a class="reference external" href="https://github.com/numpy/numpy/blob/master/numpy/distutils/conv_template.py">conv_template.py</a>.
The type specific C files generated (extension: .c)
by these modules during the build process are ready to be compiled. This
form of generic typing is also supported for C header files (preprocessed
to produce .h files).</p>
</div>
<div class="section" id="useful-functions-in-numpy-distutils-misc-util">
<h3>Useful functions in <code class="docutils literal notranslate"><span class="pre">numpy.distutils.misc_util</span></code><a class="headerlink" href="#useful-functions-in-numpy-distutils-misc-util" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">get_numpy_include_dirs()</span></code> — return a list of NumPy base
include directories. NumPy base include directories contain
header files such as <code class="docutils literal notranslate"><span class="pre">numpy/arrayobject.h</span></code>, <code class="docutils literal notranslate"><span class="pre">numpy/funcobject.h</span></code>
etc. For installed NumPy the returned list has length 1
but when building NumPy the list may contain more directories,
for example, a path to <code class="docutils literal notranslate"><span class="pre">config.h</span></code> file that
<code class="docutils literal notranslate"><span class="pre">numpy/base/setup.py</span></code> file generates and is used by <code class="docutils literal notranslate"><span class="pre">numpy</span></code>
header files.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">append_path(prefix,path)</span></code> — smart append <code class="docutils literal notranslate"><span class="pre">path</span></code> to <code class="docutils literal notranslate"><span class="pre">prefix</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">gpaths(paths,</span> <span class="pre">local_path='')</span></code> — apply glob to paths and prepend
<code class="docutils literal notranslate"><span class="pre">local_path</span></code> if needed.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">njoin(*path)</span></code> — join pathname components + convert <code class="docutils literal notranslate"><span class="pre">/</span></code>-separated path
to <code class="docutils literal notranslate"><span class="pre">os.sep</span></code>-separated path and resolve <code class="docutils literal notranslate"><span class="pre">..</span></code>, <code class="docutils literal notranslate"><span class="pre">.</span></code> from paths.
Ex. <code class="docutils literal notranslate"><span class="pre">njoin('a',['b','./c'],'..','g')</span> <span class="pre">-&gt;</span> <span class="pre">os.path.join('a','b','g')</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">minrelpath(path)</span></code> — resolves dots in <code class="docutils literal notranslate"><span class="pre">path</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">rel_path(path,</span> <span class="pre">parent_path)</span></code> — return <code class="docutils literal notranslate"><span class="pre">path</span></code> relative to <code class="docutils literal notranslate"><span class="pre">parent_path</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">def</span> <span class="pre">get_cmd(cmdname,_cache={})</span></code> — returns <code class="docutils literal notranslate"><span class="pre">numpy.distutils</span></code>
command instance.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">all_strings(lst)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">has_f_sources(sources)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">has_cxx_sources(sources)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">filter_sources(sources)</span></code> — return <code class="docutils literal notranslate"><span class="pre">c_sources,</span> <span class="pre">cxx_sources,</span>
<span class="pre">f_sources,</span> <span class="pre">fmodule_sources</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">get_dependencies(sources)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">is_local_src_dir(directory)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">get_ext_source_files(ext)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">get_script_files(scripts)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">get_lib_source_files(lib)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">get_data_files(data)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">dot_join(*args)</span></code> — join non-zero arguments with a dot.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">get_frame(level=0)</span></code> — return frame object from call stack with given level.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">cyg2win32(path)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">mingw32()</span></code> — return <code class="docutils literal notranslate"><span class="pre">True</span></code> when using mingw32 environment.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">terminal_has_colors()</span></code>, <code class="docutils literal notranslate"><span class="pre">red_text(s)</span></code>, <code class="docutils literal notranslate"><span class="pre">green_text(s)</span></code>,
<code class="docutils literal notranslate"><span class="pre">yellow_text(s)</span></code>, <code class="docutils literal notranslate"><span class="pre">blue_text(s)</span></code>, <code class="docutils literal notranslate"><span class="pre">cyan_text(s)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">get_path(mod_name,parent_path=None)</span></code> — return path of a module
relative to parent_path when given. Handles also <code class="docutils literal notranslate"><span class="pre">__main__</span></code> and
<code class="docutils literal notranslate"><span class="pre">__builtin__</span></code> modules.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">allpath(name)</span></code> — replaces <code class="docutils literal notranslate"><span class="pre">/</span></code> with <code class="docutils literal notranslate"><span class="pre">os.sep</span></code> in <code class="docutils literal notranslate"><span class="pre">name</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">cxx_ext_match</span></code>, <code class="docutils literal notranslate"><span class="pre">fortran_ext_match</span></code>, <code class="docutils literal notranslate"><span class="pre">f90_ext_match</span></code>,
<code class="docutils literal notranslate"><span class="pre">f90_module_name_match</span></code></p></li>
</ul>
</div>
<div class="section" id="numpy-distutils-system-info-module">
<h3><code class="docutils literal notranslate"><span class="pre">numpy.distutils.system_info</span></code> module<a class="headerlink" href="#numpy-distutils-system-info-module" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">get_info(name,notfound_action=0)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">combine_paths(*args,**kws)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">show_all()</span></code></p></li>
</ul>
</div>
<div class="section" id="numpy-distutils-cpuinfo-module">
<h3><code class="docutils literal notranslate"><span class="pre">numpy.distutils.cpuinfo</span></code> module<a class="headerlink" href="#numpy-distutils-cpuinfo-module" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">cpuinfo</span></code></p></li>
</ul>
</div>
<div class="section" id="numpy-distutils-log-module">
<h3><code class="docutils literal notranslate"><span class="pre">numpy.distutils.log</span></code> module<a class="headerlink" href="#numpy-distutils-log-module" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">set_verbosity(v)</span></code></p></li>
</ul>
</div>
<div class="section" id="numpy-distutils-exec-command-module">
<h3><code class="docutils literal notranslate"><span class="pre">numpy.distutils.exec_command</span></code> module<a class="headerlink" href="#numpy-distutils-exec-command-module" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">get_pythonexe()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">find_executable(exe,</span> <span class="pre">path=None)</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">exec_command(</span> <span class="pre">command,</span> <span class="pre">execute_in='',</span> <span class="pre">use_shell=None,</span> <span class="pre">use_tee=None,</span> <span class="pre">**env</span> <span class="pre">)</span></code></p></li>
</ul>
</div>
</div>
<div class="section" id="the-init-py-file">
<h2>The <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code> file<a class="headerlink" href="#the-init-py-file" title="Permalink to this headline">¶</a></h2>
<p>The header of a typical SciPy <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code> is:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Package docstring, typically with a brief description and function listing.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="c1"># py3k related imports</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">division</span><span class="p">,</span> <span class="n">print_function</span><span class="p">,</span> <span class="n">absolute_import</span>

<span class="c1"># import functions into module namespace</span>
<span class="kn">from</span> <span class="nn">.subpackage</span> <span class="kn">import</span> <span class="o">*</span>
<span class="o">...</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="nb">dir</span><span class="p">()</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">s</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;_&#39;</span><span class="p">)]</span>

<span class="kn">from</span> <span class="nn">numpy.testing</span> <span class="kn">import</span> <span class="n">Tester</span>
<span class="n">test</span> <span class="o">=</span> <span class="n">Tester</span><span class="p">()</span><span class="o">.</span><span class="n">test</span>
<span class="n">bench</span> <span class="o">=</span> <span class="n">Tester</span><span class="p">()</span><span class="o">.</span><span class="n">bench</span>
</pre></div>
</div>
<p>Note that NumPy submodules still use a file named <code class="docutils literal notranslate"><span class="pre">info.py</span></code> in which the
module docstring and <code class="docutils literal notranslate"><span class="pre">__all__</span></code> dict are defined.  These files will be removed
at some point.</p>
</div>
<div class="section" id="extra-features-in-numpy-distutils">
<h2>Extra features in NumPy Distutils<a class="headerlink" href="#extra-features-in-numpy-distutils" title="Permalink to this headline">¶</a></h2>
<div class="section" id="specifying-config-fc-options-for-libraries-in-setup-py-script">
<h3>Specifying config_fc options for libraries in setup.py script<a class="headerlink" href="#specifying-config-fc-options-for-libraries-in-setup-py-script" title="Permalink to this headline">¶</a></h3>
<p>It is possible to specify config_fc options in setup.py scripts.
For example, using</p>
<blockquote>
<div><dl class="simple">
<dt>config.add_library(‘library’,</dt><dd><p>sources=[…],
config_fc={‘noopt’:(__file__,1)})</p>
</dd>
</dl>
</div></blockquote>
<p>will compile the <code class="docutils literal notranslate"><span class="pre">library</span></code> sources without optimization flags.</p>
<p>It’s recommended to specify only those config_fc options in such a way
that are compiler independent.</p>
</div>
<div class="section" id="getting-extra-fortran-77-compiler-options-from-source">
<h3>Getting extra Fortran 77 compiler options from source<a class="headerlink" href="#getting-extra-fortran-77-compiler-options-from-source" title="Permalink to this headline">¶</a></h3>
<p>Some old Fortran codes need special compiler options in order to
work correctly. In order to specify compiler options per source
file, <code class="docutils literal notranslate"><span class="pre">numpy.distutils</span></code> Fortran compiler looks for the following
pattern:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">CF77FLAGS</span><span class="p">(</span><span class="o">&lt;</span><span class="n">fcompiler</span> <span class="nb">type</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">=</span> <span class="o">&lt;</span><span class="n">fcompiler</span> <span class="n">f77flags</span><span class="o">&gt;</span>
</pre></div>
</div>
<p>in the first 20 lines of the source and use the <code class="docutils literal notranslate"><span class="pre">f77flags</span></code> for
specified type of the fcompiler (the first character <code class="docutils literal notranslate"><span class="pre">C</span></code> is optional).</p>
<p>TODO: This feature can be easily extended for Fortran 90 codes as
well. Let us know if you would need such a feature.</p>
</div>
</div>
</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>